#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2019 crane <crane@gosun>
#
# Distributed under terms of the MIT license.

"""

"""

from itertools import count
from hashlib import md5


def add_prefix_pad0(input_str, zero_n):
    prefix_0 = zero_n * '0'

    for i in count():
        bytes = (input_str + str(i)).encode('utf8')
        hashid = md5(bytes).hexdigest()
        if hashid.startswith(prefix_0):
            print(input_str, zero_n, i)
            break

    return i


def main():
    print("start main")

    # result = add_prefix_pad0("hello", 4)
    # result = add_prefix_pad0("hellosdf", 4)
    # result = add_prefix_pad0("crane", 4)

    # result = add_prefix_pad0("crane", 5)
    # result = add_prefix_pad0("crane", 6)
    # result = add_prefix_pad0("crane", 7)

    # hello 4 105484
    # hellosdf 4 78913
    # crane 4 141330
    # crane 5 2550788
    # crane 6 2550788
    # crane 7 94892781

    result = add_prefix_pad0("crane", 8)

    # result = add_prefix_pad0("crane", 8)

if __name__ == "__main__":
    main()
